import { useState, useEffect } from 'react'

import styles from './index.module.less'
import { ApiRequest, apis } from '@/service'
import GetWBIParams from '@/apps/bilibili/utils/GetWBI'

const {
  test: {
    search,
    searchByType
  }
} = apis.BilibiliService

const Test = (props: any) => {

  useEffect(() => {
    queryFunc()
    queryByType('video')
    queryByType('user')
  }, [])

  const queryFunc = async () => {
    const params = {
      keyword: '洛天依',
      search_type: 'video',
      order: 'totalrank',
      duration: 0,
      tids: 0,
      page: 1,
    }
    ApiRequest({
      api: search, params, headers: {
        'Origin': "https://bilibili.com",
        'Referer': 'https://bilibili.com'
    } }).then((res: any) => {
      console.log('search', res)
    })
  }

  const queryByType = async (type: string) => {
    const params = await GetWBIParams({
      keyword: '洛天依',
      search_type: 'video',
    })
    ApiRequest({ api: searchByType, params }).then((res: any) => {
      console.log('searchByType', type, res)
    })
  }

  return <div className={styles.testPage}></div>
}

export default Test
